<?php
/**
 * Created by PhpStorm.
 * User: liuhongchuan
 * Date: 2018/6/27
 * Time: 17:57
 */

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ShareController extends Controller
{
    /**
     * 健康报告
     *
     * @param Request $request
     */
    public function healthReport(Request $request)
    {
        return view('home.health-report', ['request' => $request->all()]);
    }

    /**
     * 饮食分析
     *
     * @param Request $request
     */
    public function eatAnalyse(Request $request)
    {
        $data = $request->all();
        if ($data['fat_weight'] < $data['min_fat_weight']) {
            $data['fat_compare'] = -1;
            $diff_fat_weight = $data['min_fat_weight'] - $data['fat_weight'];
            $data['fat_analyse'] = "您今日的脂肪摄入量为{$data['fat_weight']}g，还应该补充摄入{$diff_fat_weight}g。必需脂肪酸不仅可调节血脂、防治冠心病，且与智力发育、记忆等生理功能相关。富含ω-3脂肪酸的有亚麻籽、菜籽油，三文鱼、奶酪、牛油果，其他油类推荐橄榄油、山茶油。每日可适当吃一小把新鲜原味的多种坚果，如花生、核桃、夏威夷果、大杏仁、榛子、碧根果、开心果、松子、腰果等，补充优质脂肪酸。";
        } elseif ($data['fat_weight'] > $data['max_fat_weight']) {
            $data['fat_compare'] = 1;
            $diff_fat_weight = $data['fat_weight'] - $data['max_fat_weight'];
            $data['fat_analyse'] = "您今日的脂肪摄入量为{$data['fat_weight']}g，超出推荐量{$diff_fat_weight}g。过多的饱和脂肪酸不利于机体健康，也会影响您的完美体型。建议您适当减少奶油、蛋糕、食用油、肥肉、油炸、煎烤类食物，保证充足的优质脂肪，如坚果、鱼肉等，食不过量。";
        } else {
            $data['fat_compare'] = 0;
            $data['fat_analyse'] = "";
        }

        if ($data['protein_weight'] < $data['min_protein_weight']) {
            $data['protein_compare'] = -1;
            $diff_protein_weight = $data['min_protein_weight'] - $data['protein_weight'];
            $data['protein_analyse'] = "您今日的蛋白质摄入量为{$data['protein_weight']}g，还应该补充摄入{$diff_protein_weight}g。优质蛋白质应占总蛋白质的1/3~1/2。建议您可适当摄入鱼、奶、瘦肉、蛋类及大豆类食物，如鳕鱼、带鱼、黄鱼、秋刀鱼、金枪鱼等海鱼，鸡脯肉、牛肉、牛奶、驴肉、虾肉、鸡蛋以及豆腐、现磨豆浆等豆制品。";
        } elseif ($data['protein_weight'] > $data['max_protein_weight']) {
            $data['protein_compare'] = 1;
            $diff_protein_weight = $data['protein_weight'] - $data['max_protein_weight'];
            $data['protein_analyse'] = "您今日的蛋白质摄入量为{$data['protein_weight']}g，超出推荐量{$diff_protein_weight}g。建议您调整膳食比例，在保证优质蛋白质充足的情况下，鱼、肉、蛋、奶类可适当减少摄入，食不过量。";
        } else {
            $data['protein_compare'] = 0;
            $data['protein_analyse'] = "";
        }

        if ($data['carbohydrate_weight'] < $data['min_carbohydrate_weight']) {
            $data['carbohydrate_compare'] = -1;
            $diff_carbohydrate_weight = $data['min_carbohydrate_weight'] - $data['carbohydrate_weight'];
            $data['carbohydrate_analyse'] = "您今日的碳水化合物摄入量为{$data['carbohydrate_weight']}g，还应该摄入{$diff_carbohydrate_weight}g。由于葡萄糖是人体大脑唯一的能量来源，为了保持大脑充足的能量供应，建议您可适当增加主食等复合糖类食物，如全麦面包、玉米、番薯、杂豆饭、藜麦、薏米、糙米、燕麦等。且用充足的碳水化合物来供能可以节省蛋白质，使其充分发挥修复细胞和组织的功效。注：不建议直接进食麦芽糖、  白糖、糖浆等精炼糖类，精炼糖进入人体后释放能量的速度比较快，易导致体内血糖突然升高和下降，反而不利于环节大脑疲劳。）";
        } elseif ($data['carbohydrate_weight'] > $data['max_carbohydrate_weight']) {
            $data['carbohydrate_compare'] = 1;
            $diff_carbohydrate_weight = $data['max_carbohydrate_weight'] - $data['carbohydrate_weight'];
            $data['carbohydrate_analyse'] = "您今日的碳水化合物摄入量为{$data['carbohydrate_weight']}g，超出推荐量{$diff_carbohydrate_weight}g。建议您适当减少精白米面的摄入，多纤维蔬菜、魔芋等食物可适当增加饱腹感而不增加热量，合理的进餐顺序也可帮助您达到平衡膳食，如汤水类--蔬菜类--菌菇类--肉鱼类--主食，食不过量。";
        } else {
            $data['carbohydrate_compare'] = 0;
            $data['carbohydrate_analyse'] = "";
        }
        return view('home.eat-analyse', ['request' => $data]);
    }
}
